
import vue from '@vitejs/plugin-vue'
import { viteMockServe } from 'vite-plugin-mock'
import { resolve } from 'path'

const pathResolve = (dir) => {
  return resolve(__dirname, ".", dir)
}

const alias = {
  '@': pathResolve("src")
}
// import.meta.env

/**
 * @description-en vite document address
 * @description-cn vite官网
 * https://vitejs.cn/config/ */
export default ({ command }) => {
  const prodMock = true;
  return {
    base: './',
    
    resolve: {
      alias
    },
    server: {
      port: 8080,
      host: '0.0.0.0',
      public: '192.168.1.197',
      open: false,
      // https://www.fastmock.site/mock/48cab8545e64d93ff9ba66a87ad04f6b/
      proxy: { // 代理配置
        '/dev': ''
      },
    },
    build: {
      rollupOptions: {
        output: {
          manualChunks: {
            'echarts': ['echarts']
          },
          chunkFileNames: 'static/assets/js/[name]-[hash].js',
          entryFileNames: 'static/assets/js/[name]-[hash].js',
          assetFileNames: 'static/assets/[ext]/[name]-[hash].[ext]',
        }
      },
      // base: './', // 这里更改打包相对绝对路径
      minify: true, // 是否压缩代码
      sourceMap: true, // 是否生成sourceMap
      outDir:'dist',
    },
    plugins: [
      vue(),
      viteMockServe({
        mockPath: 'mock',
        localEnabled: command === 'serve',
        prodEnabled: command !== 'serve' && prodMock,
        watchFiles: true,
        logger: true,
      }),
    ],
    css: {
      postcss: {
        plugins: [
          {
            postcssPlugin: 'internal:charset-removal',
            AtRule: {
              charset: (atRule) => {
                if (atRule.name === 'charset') {
                  atRule.remove();
                }
              }
            }
          }
        ],
      },
    }
  };
}
